package com.caiyigo.baihua.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.caiyigo.baihua.Const.Const;
import com.caiyigo.baihua.dto.DataGrid;
import com.caiyigo.baihua.dto.LogDto;
import com.caiyigo.baihua.dto.Pager;
import com.caiyigo.baihua.dto.UserDto;
import com.caiyigo.baihua.model.SystemLog;
import com.caiyigo.baihua.model.SystemRole;
import com.caiyigo.baihua.model.SystemUser;
import com.caiyigo.baihua.service.LogService;
import com.caiyigo.baihua.shiro.ShiroExt;
import com.caiyigo.baihua.utils.ListUtil;
import com.github.miemiedev.mybatis.paginator.domain.Order;
import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;

/**
 * @author caihaihui
 * 
 */
@Controller
@RequestMapping(value = "/system/log")
public class LogController {
	@Autowired
	LogService logService;

	@RequestMapping(value = "/list", method = RequestMethod.POST)
	public @ResponseBody
	DataGrid<LogDto> list(LogDto log, Pager page) {
		// 表单查询条件组装

		List<Order> orders = new ArrayList<Order>();
		orders.add(Order.create(page.getSort(), page.getOrder()));
		PageList<LogDto> pageList = (PageList<LogDto>) logService
				.getUserList( log,new PageBounds(page.getPage(), page.getRows(),
						orders, true));

		return new DataGrid<LogDto>(pageList.getPaginator().getTotalCount(),
				pageList.getPaginator().getPage(), pageList);

	}
}
